﻿using System.Collections;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace SiteFox.WebParts.Standard
{
    [AspNetHostingPermission(SecurityAction.Demand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand,
      Level = AspNetHostingPermissionLevel.Minimal)]

    public class PageViewWP : WebPart
    {
        Literal _IFrame;

        private string _IFrameCssClass = "";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [WebDescription("IFrame CssClass")]
        [WebDisplayName("IFrame CssClass")]
        public string IFrameCssClass
        {
            get { return _IFrameCssClass; }
            set { _IFrameCssClass = value; }
        }
        
        private string _PageUrl = "";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [WebDescription("Enter page url")]
        [WebDisplayName("Page url")]
        public string PageUrl
        {
            get { return _PageUrl; }
            set { _PageUrl = value; }
        }

        private string _IFrameHeight = "";
        [Personalizable()]
        [WebBrowsable(true)]
        [WebDescription("Height")]
        [WebDisplayName("Height")]
        public string IFrameHeight
        {
            get { return _IFrameHeight; }
            set { _IFrameHeight = value; }
        }

        private string _IFrameWidth = "";
        [Personalizable()]
        [WebBrowsable(true)]
        [WebDescription("Width")]
        [WebDisplayName("Width")]
        public string IFrameWidth
        {
            get { return _IFrameWidth; }
            set { _IFrameWidth = value; }
        }

        private bool _FrameBorder = true;
        [Personalizable()]
        [WebBrowsable(true)]
        [WebDescription("FrameBorder")]
        [WebDisplayName("FrameBorder")]
        public bool FrameBorder
        {
            get { return _FrameBorder; }
            set { _FrameBorder = value; }
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();
            _IFrame = new Literal();
            _IFrame.Text = "<iframe src=\"" + _PageUrl + "\" frameborder=\"" + _FrameBorderValue() + "\" class=\"" + _IFrameCssClass + "\" height=\"" + _IFrameHeight + "\" width=\"" + _IFrameWidth + "\"></iframe>";
            Controls.Add(_IFrame);
        }
        string _FrameBorderValue() 
        {
            string _Value = "";
            if (_FrameBorder) 
            {
                _Value = "1";
            }
            else 
            {
                _Value = "0";
            }
            return _Value;
        }
    }
}
